import request from './request.js';

//登录系统
export const loginUser = (user) => {
  return request({
    method: 'POST',
    url: `/users/login`,
    data: user,
  });
};

//注册账号
export const registerUser = (user) => {
  return request({
    method: 'POST',
    url: `/users/addUser`,
    data: user,
  });
};

//查询用一个用户信息
export const getUserInfo = (user) => {
  return request({
    method: 'GET',
    url: `/users/getbyname/?username=${user.username}&type=${user.type}`,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//修改用户信息
export const updateUserInfo = (user) => {
  return request({
    method: 'POST',
    url: `/users/updateUser`,
    data: user,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//上传头像
export const uploadAvatar = (file) => {
  return request({
    method: 'POST',
    url: `users/uploadAvatar`,
    data: file,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//修改密码
export const updateUserPassword = (user) => {
  return request({
    method: 'POST',
    url: `/users/updatePassword`,
    data: user,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//获取所有用户列表
export const getAllUsers = () => {
  return request({
    method: 'GET',
    url: `/users/`,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//删除用户
export const deleteUser = (user) => {
  return request({
    method: 'DELETE',
    url: `/users/deleteUser?username=${user.username}&type=${user.type}`,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//用户重置密码
export const resetPassword = (user) => {
  return request({
    method: 'POST',
    url: `/users/resetPassword`,
    data: user,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};
//==============公告的请求==============

//获取公告列表
export const getNoticeList = () => {
  return request({
    method: 'GET',
    url: `/notices/`,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//添加公告
export const addNotice = (notice) => {
  return request({
    method: 'POST',
    url: `/notices/addNotice`,
    data: notice,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//报告路况
export const addTrafficReport = (value) => {
  return request({
    method: 'POST',
    url: `/trafficReports/add`,
    data: value,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//查看所有用户报告的路况信息
export const getAllTrafficReports = () => {
  return request({
    method: 'GET',
    url: `/trafficreports/`,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//审核路况信息
export const auditTrafficReport = (value) => {
  return request({
    method: 'POST',
    url: `/trafficreports/updateStatus`,
    data: value,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//管理员添加事件
export const addTrafficReportAdmin = (value) => {
  return request({
    method: 'POST',
    url: `/events/add`,
    data: value,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};

//查询事件列表
export const getEventList = () => {
  return request({
    method: 'GET',
    url: `/events/`,
    headers: {
      Authorization: `Bearer ${localStorage.getItem('jwtToken')}`,
    },
  });
};
